package com.sunny.l48;

public class Solution {
    public boolean isSymmetric(TreeNode root) {
        return dfs(root, root);
    }
    public boolean dfs(TreeNode node1, TreeNode node2){
        if((null == node1 && null != node2) || (null != node1 && null == node2))
            return false;
        if(null == node1 && null == node2)
            return true;
        if(node1 == node2){
            return dfs(node1.left, node2.right);
        }
        return node1.val == node2.val && dfs(node1.left, node2.right) && dfs(node1.right, node2.left);
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}
